package com.meanbean.studytime.controls;

import javafx.scene.image.Image;

/**
 * A button used in 'Study' mode.
 * @author Derek Webb
 */
public class StudyButton extends Button
{
	String guess = "";
	
	/**
	 * Creates a StudyButton.
	 * @param x The X position of this button.
	 * @param y The Y position of this button.
	 * @param answer The answer String associated with this button.
	 */
	public StudyButton(int x, int y, String answer)
	{
		super(x, y, answer);
	}
	
	public void open()
	{
		textField.setText(guess);
		
		super.open();
	}
	
	public void close()
	{
		super.close();
		
		// Store the guess
		guess = textField.getText().trim();
		
		// If the guess is correct, change the color to green
		if (guess.equalsIgnoreCase(answer))
			imageView.setImage(new Image("com/meanbean/studytime/resources/GreenButton.png"));
		// Else if the guess == "", change the color to gray
		else if (guess.equals(""))
			imageView.setImage(new Image("com/meanbean/studytime/resources/GrayButton.png"));
		// Else change it to red
		else
			imageView.setImage(new Image("com/meanbean/studytime/resources/RedButton.png"));
	}
}
